using System;
using Science.Mathematics;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter04
{
	/// <summary>
	/// Example01: Motion in a Plane
	/// A particle starts from the origin at t = 0 with an 
	/// initial velocity having an x component of 20 m/s 
	/// and a y component of -15 m/s. The particle moves in 
	/// the xy plane with an x component of acceleration only, 
	/// given by a_x = 4.0 m/s^2.
	/// (A) Determine the components of the velocity vector at 
	/// any time and the total velocity vector at any time.
	/// (B) Calculate the velocity and speed of the particle 
	/// at t = 5.0 s.
	/// (C) Determine the x and y coordinates of the particle at 
	/// any time t and the position vector at this time.
	/// </summary>
	public class Example01
	{
		public Example01()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.Velocity vini = new L.Velocity();
			vini.X = 20.0;
			vini.Y = -15.0;
			L.Vector.FunctionOfTime f = new L.Vector.FunctionOfTime(Accele);
			L.Acceleration a = new L.Acceleration();
            a.VectorFunctionOfTime = f;
			//(A,B)
			L.Time ti = new L.Time();
			ti.s = 0.0;
			L.Time tf = new L.Time();
			tf.s = 5.0;
			L.Velocity v = new L.Velocity(ti,vini,a,tf);
			result += Convert.ToString(v.X) +"  "+ Convert.ToString(v.Y)
				+"   "+ Convert.ToString(v.Norm);
			//(C)
			L.Vector.FunctionOfTime fv = new L.Vector.FunctionOfTime(Velo);
			L.Velocity vfunc = new L.Velocity();
            vfunc.VectorFunctionOfTime = fv;
			L.Position xini = new L.Position();
		    xini.X = 0.0;
			xini.Y = 0.0;
			L.Position x = new L.Position(ti,xini,vfunc,tf);
			result += "   "+Convert.ToString(x.X) 
				+"  "+ Convert.ToString(x.Y)
				+"   "+ Convert.ToString(x.Norm);
		}

		private L.Vector Velo(L.Time t)
		{
			L.Vector res = new L.Vector();
			res.X = 20.0+4.0*t.s;
			res.Y = -15.0;
			return res;
		}

		private L.Vector Accele(L.Time t)
		{
			L.Vector res = new L.Vector();
			res.X = 4.0;
			return res;
		}
	}
}
